﻿/***********************/
/* (c) Alexandru Lungu */
/*  Challenge is Life! */
/* www.challenge-me.ws */
/***********************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.ServiceModel;
using Coowork.WcfCommon;
using System.ServiceModel.Channels;

namespace Coowork.WcfClient
{
    public static class AppClient
    {

        public static Credentials Credentials { get; set; }


        static AppClient()
        {
            Credentials = new Credentials();
            Init();
        }

        //Inits the client; gets the ServerInfo
        //This is usually called by the static constructor; it will be called outside the constructor only when the server is restarted and the client was already initilized.
        public static void Init()
        {
            using (ChannelFactory<IServerInfoService> infoChannel = new ChannelFactory<IServerInfoService>("ServerInfoService"))
            {
                IServerInfoService infoProxy = infoChannel.CreateChannel();
                ServerInfo serverInfo = infoProxy.GetServerInfo();
                Credentials.ServerDateTime = serverInfo.DateTime;
                ClientCryptographer.RsaServiceProvider.FromXmlString(serverInfo.XmlKey);
            }    
        }
    }
}
